<?php
/*
Copyright (c) 2007 Adam Carter

For complete licensing information, see LICENSE.txt found in the root folder
*/
class ResultSet
{
   /**
   * @desc Holds the results returned by DataBLL
   * @var array
   */
   private $results;
   
   /**
   * @desc constructor method
   * @param array $results The results as obtained by DataBLL
   * @returns void
   */
   public function __construct($results)
   {
      $this->results = $results;
   }
   
   /**
   * @desc returns the results in array format
   * @returns array
   */
   public function toArray()
   {
      return $this->results;
   }
   
   /**
   * @desc returns the results in XML format
   * @returns String
   */
   public function toXML()
   {
      // create a new XML document
      $doc = new DomDocument('1.0');
      
      // create root node
      $root = $doc->createElement('resultSet');
      $root = $doc->appendChild($root);
      
      // process one row at a time
      foreach($this->results as $key => $value)
      {
        $occ = $doc->createElement('row');
        $occ = $root->appendChild($occ);
      
        foreach ($value as $fieldname => $fieldvalue) 
        {
         $child = $doc->createElement($fieldname);
         $child = $occ->appendChild($child);
      
         $value = $doc->createTextNode($fieldvalue);
         $value = $child->appendChild($value);
        } 
      } 
      
      // get completed xml document
      return $doc->saveXML();
   }
   
   /**
   * @desc generic toString method
   * @returns array
   */
   public function __toString()
   {
      return $this->results;
   }
}
?>
